﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Fis.Win.Forms
{
    public partial class EditForm : BaseForm
    {
        public EditForm()
        {
            InitializeComponent();
        }

        public override string Message
        {
            get
            {
                return iMessage.Caption;
            }
            set
            {
                iMessage.Caption = value;
                ShowMessage(value);
            }
        }
        protected virtual bool IsInitializeBinding { get; set; }


        private void iSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (ValidateBeforeSave())
            {
                if (SaveProcess())
                {
                    ViewResult = DialogResult.OK;
                    Close();
                }
            }
        }

        private void iSaveNew_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (ValidateBeforeSave())
                SaveNewProcess();
        }

        protected virtual bool ValidateBeforeSave()
        {
            Validate();

            return dxValidationProvider1.Validate();
        }

        protected virtual bool SaveProcess() { return true; }
        protected virtual void SaveNewProcess()
        {
            if (SaveProcess())
            {
                ViewProvider.ViewState = ViewState = Agile.Engine.View.ViewState.AddNew;
                InitializeAfterSave();
            }
        }

        protected virtual void InitializeAfterSave() { }

    }
}
